package conput;

import java.util.HashMap;

public class RWLHMServer extends Server {

    private final HashMap<Integer, String> posts = new HashMap<Integer, String>();
    private final ReadWriteLock lock = new ReadWriteLock();

    public void write(String s) throws InterruptedException {
        lock.writeLock();
        try {
            posts.put(size.getAndIncrement(), s);
        } finally {
            lock.unlockWrite();
        }
    }

    public String read(int i) throws InterruptedException {
        lock.readLock();
        try {
            return posts.get(i);
        } finally {
            lock.unlockRead();
        }
    }
}
